<?php 
include_once('connection/connection.php');
//session_start();
//ob_start();
error_reporting(0);
session_set_cookie_params(8*60*60);
ini_set('session.gc_maxlifetime', '28800');
include('header.php');
include('menu.php');
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link href="css/style_question.css" type="text/css" rel="stylesheet" />
<script language="javascript" type="text/javascript" src="js/validate.js"></script>
<title>Questionnaire No.3</title>
 <script language=javascript>
function formshowhide(id)
{
	if(id == "YES")
	{
		document.getElementById('show').style.display = "block";
	}
	else
	{
		document.getElementById('show').style.display = "none";
	}
}
</script>
</head>
<body>
<?php
$loc_id = $_SESSION['loc_id'];
$rows_num = $_SESSION['rows_num'];
if(isset($_POST['submit']))
{
		$fclick = true;
		for($i=1; $i<=$rows_num; $i++)
		{
			$hcode='ms_habit_code'.$i;
			$hname='ms_habit_name'.$i;
			$type_habit='type_habit'.$i;
			$handpump_govt='handpump_govt'.$i;
			$handpump_pvt='handpump_pvt'.$i;
			//$pipedwater='pipedwater'.$i;
			$tubewell='tubewell'.$i;
			$dugwell='dugwell'.$i;
			//$public_taps='public_taps'.$i;
			$rain_water_tank='rain_water_tank'.$i;
			$tanker_truck='tanker_truck'.$i;
			$small_tank='small_tank'.$i;
			$surface_water='surface_water'.$i;
			$irrigation_canal='irrigation_canal'.$i;
			$other_source='other_source'.$i;
			
			$hcode=$_POST[$hcode];
			$hname=$_POST[$hname];
			$type_habit=$_POST[$type_habit];
			$handpump_govt=$_POST[$handpump_govt]; 
			$handpump_pvt=$_POST[$handpump_pvt]; 
			//$pipedwater=$_POST[$pipedwater]; 
			$tubewell=$_POST[$tubewell]; 
			$dugwell=$_POST[$dugwell]; 
			//$public_taps=$_POST[$public_taps]; 
			$rain_water_tank=$_POST[$rain_water_tank]; 
			$tanker_truck=$_POST[$tanker_truck]; 
		 	$small_tank=$_POST[$small_tank]; 
			$surface_water=$_POST[$surface_water]; 
			$irrigation_canal=$_POST[$irrigation_canal]; 
			$other_source=$_POST[$other_source]; 
			$total[$i] = $handpump_govt + $handpump_pvt + $tubewell + $dugwell + $rain_water_tank + $tanker_truck + $small_tank + $surface_water + $irrigation_canal + $other_source;
			$arr_hab_count[$hname] = $total[$i];
			
			$qr1="INSERT INTO tbl_dtls_q3_water_source(loc_id, habitation_code, habitation_name,  type_habit, handpump_govt, handpump_pvt, tubewell, dugwell, rain_water_tank, tanker_truck, small_tank, surface_water, irrigation_canal, other_source) VALUES ('$loc_id', '$hcode', '$hname', '$type_habit', '$handpump_govt', '$handpump_pvt', '$tubewell', '$dugwell', '$rain_water_tank', '$tanker_truck', '$small_tank', '$surface_water', '$irrigation_canal', '$other_source')";
			$result1=mysql_query($qr1);
			if($result1)
			{
				//header('Location: questionnaire3_2.php');
				//echo "success 1";	
				$relocatePage=true;	
			}
			else 
			{
				$errorIns="Error inserting Water_source table <br>";
			}
			
			$way_pure_water='treat_water_safe'.$i;
			$treat_water_safe_other='treat_water_safe_other'.$i;		
			$w=$_POST[$way_pure_water];	
			$treat_water_safe_other=$_POST[$treat_water_safe_other];
			$way_pure_water=implode(',',$w);
			$way_pure_water=$way_pure_water . ',' . $treat_water_safe_other; 
			$qr2="INSERT INTO tbl_dtls_q3_water_safe(loc_id, habitation_code, habitation_name, way_pure_water) VALUES ('$loc_id', '$hcode', '$hname', '$way_pure_water')";
			//echo $qr2;
			$result2=mysql_query($qr2);
			if($result2)
			{
				//header('Location: questionnaire3_2.php');
				//echo "success 1";	
				$relocatePage=true;	
			}
			else 
			{
				$errorIns="Error inserting Water_safe table <br>";
			} 
			
		}	
			$totalsum = array_sum($total);
			$_SESSION['sum2']=$totalsum;
			$_SESSION['arrSource'] = $arr_hab_count;
			
			//////////////////////////////////////////////////
			$expire=time()+60*60*24;  // 1 day
			setcookie("sum2", $_SESSION['sum2'], $expire);
			setcookie("arrHabSource", $_SESSION['arrHabSource'], $expire);
			$time_offset ="525"; // Change this to your time zone
			$time_a = ($time_offset * 120);
			$last_login =date("D M j G:i:s T Y",time() + $time_a);
			$dateTime = new DateTime("now");
			$dateTimeZone = new DateTimeZone('Asia/Kolkata');
			$dateTime->setTimezone($dateTimeZone);
			$datet=$dateTime->format("d-m-Y H:i:s");
			/////////////////////////////////////////////////////
			
			$phed_water=$_POST['phed_water'];
			$you_water=$_POST['treat_water'];
			$qr3="UPDATE tbl_dtls_q3_loc SET phed_water_safe = '$phed_water', you_water_safe = '$you_water' WHERE id='$loc_id'";	
			$result3=mysql_query($qr3);
			if($result3)
			{
				$relocatePage=true;
				//echo "success 2";
			}
			else 
			{
				$errorIns.="Error inserting phed_water_safe <br>";
			}
			if($errorIns==0) 
			{
				if($totalsum == 0)
				{
					header('Location: questionnaire3_5.php');
				}
				else
				{
					header('Location: questionnaire3_4.php');
				}
			}
			else 
			{
				echo $errorIns;exit;
			}	
}
else
{
	$fclick = false;
	$flag=0;
}
?>
<div align="center">
<form action="" method="post" enctype="multipart/form-data" name="questionnaire3_3" id="questionnaire3_3" onSubmit="return validate3()">
	<table border="0" width="800" id="table1" cellspacing="0" cellpadding="0">
		<tr>
			<td height="30">
			<p align="center">
			<font face="Verdana" style="font-size: 10pt; font-weight: 700" color="#000000">
			Questionnaire No. 3</font></p></td>
		</tr>
		<tr>
			<td height="19">
			<p align="center">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">For 
			Field Survey (Village Level questionnaire) </font></p></td>
		</tr>
		<tr>
			<td height="18">
			<p align="center">
			<font style="font-size: 8.5pt" face="Arial" color="#000000">Page 3</font></p></td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#EEEEEE" height="22"><font color="#000000">&nbsp;
			<span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt">4. </font></span></font>
			<span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">MAIN 
			SOURCE OF DRINKING WATER (As existing in Main Village and Other 
			habitations) </font></span></td>
		</tr>
		<tr>
			<td>
			<table border="0" width="900" id="table4" cellspacing="1" cellpadding="0" bgcolor="#FDF9EE">
				<tr>
					<td colspan="14"><span style="font-size: 4pt">&nbsp;</span></td>
				</tr>
				<tr>
					<td width="151" align="center" rowspan="2" bgcolor="#F7E6B7">
						<font style="font-size: 8.5pt; font-style:normal" face="Verdana" color="#990000">
						Habitation</font>				  </td>
				  <td align="center" width="49" rowspan="2" bgcolor="#F7E6B7">
					<address>
						<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">
						Type MH/ OH</font></address>
				  </td>
					<td height="27" colspan="2" align="center" bgcolor="#F7E6B7">
					<address>
						<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">Hand Pump</font>
					</address>
				  </td>
					
					<td align="center" width="65" rowspan="2" bgcolor="#F7E6B7"><address><font face="Verdana" color="#990000"><span style="font-size: 8.5pt; font-style: normal">Tube Well(No.)</span>                    </font>
					</address>
				  </td>
					<td align="center" width="64" rowspan="2" bgcolor="#F7E6B7">
					<address>
						<span style="font-style: normal">
						<font face="Verdana" style="font-size: 8.5pt" color="#990000">Dug Well(No.)</font></span>
					</address>
				  </td>
					
					<td align="center" width="76" rowspan="2" bgcolor="#F7E6B7">
					<font face="Verdana" color="#990000">
					<span style="font-size: 8.5pt; font-style: normal">Rain Water Tanka(No.)</span></font></td>
					<td align="center" width="63" rowspan="2" bgcolor="#F7E6B7">
					<font face="Verdana" color="#990000">
					<span style="font-size: 8.5pt; font-style: normal">Tanker Truck(No.)</span></font></td>
					<td align="center" width="55" rowspan="2" bgcolor="#F7E6B7"><address><span style="font-style: normal; font-size: 8.5pt"><font face="Verdana" color="#990000">Cart With small Tank(No.)</font></span>
					</address>
				  </td>
					<td align="center" width="111" rowspan="2" bgcolor="#F7E6B7">
					<font face="Verdana" color="#990000">
					<span style="font-size: 8.5pt; font-style: normal">Surface 
					water resources (River/ Dam/ Lake/ Pond/ Stream(No.)</span></font></td>
					<td align="center" width="57" rowspan="2" bgcolor="#F7E6B7">
					<font face="Verdana" color="#990000">
					<span style="font-style: normal; font-size: 8.5pt">Irrigation Canal(No.)</span></font></td>
					<td align="center" width="75" rowspan="2" bgcolor="#F7E6B7">
					<font face="Verdana" color="#990000">
					<span style="font-size: 8.5pt; font-style: normal">Others 
					(Specify Baori, public tanka(No.)</span></font></td>
				</tr>
				<tr>
					<td align="center" width="67" valign="top" bgcolor="#F7E6B7">
					<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">
					Govt.(No.)</font></td>
					<td align="center" width="54" valign="top" bgcolor="#F7E6B7">
					<font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#990000">
					Pvt.(No.)</font></td>
				</tr>
				<?php
				$q5="SELECT DISTINCT  habit_name, habit_code FROM tbl_dtls_q3_habit WHERE status_e_nt='Existing' AND loc_id='$loc_id' order by habit_code asc";
				//echo $q5;
				$result5=mysql_query($q5);
				$i=1;
			    while(list($name, $id)=mysql_fetch_array($result5))
				{
				//echo "name=" . $name;
				//echo "id=" . $id;
					?>
				<tr>
					<td width="151" align="center">
						<input type="text" name="ms_habit_name<?php echo $i;?>" id="ms_habit_name<?php echo $i;?>" value="<?php echo $name;?>" size="20" class="txt4" readonly />
						<input type="hidden" name="ms_habit_code<?php echo $i;?>" id="ms_habit_code<?php echo $i;?>" value="<?php echo $id;?>" size="20" class="txt4" />
				  </td>
				  <td align="center" width="49"><input type="text" name="type_habit<?php echo $i;?>" id="type_habit<?php echo $i;?>" value="<?php if($i==1){ echo "MH"; } else { echo "OH"; } ?>" size="2" class="txt_1" readonly/></td>
					<td width="67" align="center">
				  <input type="text" name="handpump_govt<?php echo $i;?>" id="handpump_govt<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="54" align="center">
				  <input type="text" name="handpump_pvt<?php echo $i;?>" id="handpump_pvt<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="65" align="center">
				  <input type="text" name="tubewell<?php echo $i;?>" id="tubewell<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="64" align="center">
				  <input type="text" name="dugwell<?php echo $i;?>" id="dugwell<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="76" align="center">
				  <input type="text" name="rain_water_tank<?php echo $i;?>" id="rain_water_tank<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="63" align="center">
				  <input type="text" name="tanker_truck<?php echo $i;?>" id="tanker_truck<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="55" align="center">
				  <input type="text" name="small_tank<?php echo $i;?>" id="small_tank<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="111" align="center">
				  <input type="text" name="surface_water<?php echo $i;?>" id="surface_water<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="57" align="center">
				  <input type="text" name="irrigation_canal<?php echo $i;?>" id="irrigation_canal<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
					<td width="75" align="center">
				  <input type="text" name="other_source<?php echo $i;?>" id="other_source<?php echo $i;?>" size="20" class="txt6" value="0" onFocus="blank(this)" onBlur="unblank(this);numeric(this)"></td>
				</tr>
				<?php  $i++;
				} ?>
			<input type="hidden" name="handpumpcount" id="handpumpcount" value="<?php echo $i; ?>">
				</table>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#EEEEEE" height="22"><font color="#000000">
			<span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt">&nbsp; 5.&nbsp; </font>
			</span></font><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">Do PHED 
			Treat Water to make it safe:&nbsp;&nbsp;&nbsp; </font></span></td>
		</tr>
		<tr>
			<td>
			<table border="0" width="100%" id="table5" cellspacing="0" cellpadding="0" bgcolor="#FDF9EE">
				<tr>
					<td width="70">&nbsp;</td>
					<td width="70">
					<p align="center">
					<font style="font-size: 8.5pt" face="Arial" color="#000000">
					<input type="radio" name="phed_water" id="phed_water" value="YES" checked/> Yes</font></td>
					<td width="70">
					<p align="center">
					<font style="font-size: 8.5pt" face="Arial" color="#000000">
					<input type="radio" name="phed_water" id="phed_water" value="NO" />No</font></td>
					<td width="87">
					<p align="center">
					<font style="font-size: 8.5pt" face="Arial" color="#000000">
					<font color="#F7E6B7">
					<input type="radio" name="phed_water" id="phed_water" value="DNK" /></font> Do Not Know</font></td>
					<td width="313">&nbsp;</td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#EEEEEE" height="22"><font color="#000000">
			<span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt">&nbsp; 6.&nbsp; </font>
			</span></font><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">Do you 
			treat your water to make it safe:</font></span></td>
		</tr>
		<tr>
			<td>
			<table border="0" width="100%" id="table6" cellspacing="0" cellpadding="0" bgcolor="#FDF9EE">
				<tr>
					<td width="70">&nbsp;</td>
					<td width="70">
					<p align="center">
					<font style="font-size: 8.5pt" face="Arial" color="#000000">
				<input type="radio" name="treat_water" id="treat_water" value="YES" onClick="formshowhide('YES')" checked /> Yes</font></p></td>
					<td width="70">
					<p align="center">
					<font style="font-size: 8.5pt" face="Arial" color="#000000">
					<input type="radio" name="treat_water" id="treat_water" value="NO" onClick="formshowhide('NO')" />No</font></p></td>
					<td width="87">
					<p align="center">
					<font style="font-size: 8.5pt" face="Arial" color="#000000">
					<input type="radio" name="treat_water" id="treat_water" value="DNK" onClick="formshowhide('DNK')" /> Do Not Know</font></p></td>
					<td width="313">&nbsp;</td>
				</tr>
			</table>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td bgcolor="#EEEEEE" height="22"><span style="font-weight: 700">
			<font face="Arial" style="font-size: 8.5pt" color="#000000">&nbsp; 
			If yes : </font></span></td>
		</tr>
		<tr>
			<td>
				<div id="show">
				<table border="0" width="900" id="table7" cellspacing="1" cellpadding="0" bgcolor="#FDF9EE">
					<tr>
						<td colspan="12"><span style="font-size: 4pt">&nbsp;</span></td>
					</tr>
					<tr>
						<td width="145" align="center" valign="top" bgcolor="#F7E6B7">
							<address>
							<font style="font-size: 8.5pt; font-style:normal" face="Verdana" color="#990000">Name of Habitation</font></address>					  </td>
								<td align="center" width="88" valign="top" bgcolor="#F7E6B7">
									<span style="font-style: normal">
									<font face="Verdana" style="font-size: 8.5pt" color="#990000">
									Boil</font></span>								</td>
								<td align="center" width="88" valign="top" bgcolor="#F7E6B7">
									<span style="font-style: normal">
									<font face="Verdana" style="font-size: 8.5pt" color="#990000">
									Use Alum</font></span>								</td>
								
								<td align="center" width="75" valign="top" bgcolor="#F7E6B7">
									<font face="Verdana" style="font-size: 8.5pt" color="#990000">
									Add Bleach/ powder chorine Tablets </font></td>
								<td align="center" width="59" valign="top" bgcolor="#F7E6B7">
									<font style="font-size: 8.5pt" face="Verdana" color="#990000">
									Strain through a cloth</font></td>
								
								<td align="center" width="93" valign="top" bgcolor="#F7E6B7">
									<font face="Verdana" style="font-size: 8.5pt" color="#990000">
									Use water Filter (Ceramic / Sand / Composite)</font></td>
								<td align="center" width="76" valign="top" bgcolor="#F7E6B7">
									<font face="Verdana" style="font-size: 8.5pt" color="#990000">
									Use Electronic Purifier</font></td>
								<td align="center" width="77" valign="top" bgcolor="#F7E6B7">
									<font face="Verdana" style="font-size: 8.5pt" color="#990000">
									Let it stand and settle</font></td>
								<td align="center" width="71" valign="top" bgcolor="#F7E6B7">
									<span style="font-style: normal">
									<font face="Verdana" style="font-size: 8.5pt" color="#990000">
									DDFU</font></span></td>
								<td align="center" width="117" valign="top" bgcolor="#F7E6B7">
									<font style="font-size: 8.5pt" face="Verdana" color="#990000">
									Others (Specify)</font></td>
								<!--<td align="center" width="60" valign="top" bgcolor="#F7E6B7">
									<font face="Verdana" style="font-size: 8.5pt" color="#990000">
									Don't Know</font>
								</td>-->
				  </tr>
				<?php
				$q5="SELECT DISTINCT  habit_name, habit_code FROM tbl_dtls_q3_habit WHERE status_e_nt='Existing' AND loc_id='$loc_id' order by habit_code asc";
				//echo $q5;
				$result5=mysql_query($q5);
				$i=1;
			    while(list($name, $id)=mysql_fetch_array($result5))
				{
					//echo $key;echo $val;exit;
					?>
				<tr>
					<td width="145" align="center">
						<input type="text" name="habit_name<?php echo $i;?>" id="habit_name<?php echo $i;?>" value="<?php echo $name;?>" size="20" class="txt4" readonly />
						<input type="hidden" name="habit_code<?php echo $i;?>" id="habit_code<?php echo $i;?>" value= "<?php echo $id;?>" size="20" class="txt4" />				  </td>
					<td width="88" align="center"><font style="font-size: 8.5pt" face="Arial" color="#000000">
				  <input type="checkbox" name="treat_water_safe<?php echo $i;?>[]" id="treat_water_safe<?php echo $i;?>[]" value="Boil" /></font></td>
					<td width="88" align="center"><font style="font-size: 8.5pt" face="Arial" color="#000000">
				  <input type="checkbox" name="treat_water_safe<?php echo $i;?>[]" id="treat_water_safe<?php echo $i;?>[]" value="Use Alum" /></font></td>
					<td width="75" align="center"><font style="font-size: 8.5pt" face="Arial" color="#000000">
				  <input type="checkbox" name="treat_water_safe<?php echo $i;?>[]" id="treat_water_safe<?php echo $i;?>[]" value=" Add Bleach/Powder Chlorine Tablets" /></font></td>
					<td width="59" align="center"><font style="font-size: 8.5pt" face="Arial" color="#000000">
				  <input type="checkbox" name="treat_water_safe<?php echo $i;?>[]" id="treat_water_safe<?php echo $i;?>[]" value="Strain through a cloth" /></font></td>
					<td width="93" align="center"><font style="font-size: 8.5pt" face="Arial" color="#000000">
				  <input type="checkbox" name="treat_water_safe<?php echo $i;?>[]" id="treat_water_safe<?php echo $i;?>[]" value="Use water Filter (Ceramic/Sand/Composite)" /></font></td>
					<td width="76" align="center"><font style="font-size: 8.5pt" face="Arial" color="#000000">
				  <input type="checkbox" name="treat_water_safe<?php echo $i;?>[]" id="treat_water_safe<?php echo $i;?>[]" value="Use Electronic Purifier" /></font></td>
					<td width="77" align="center"><font style="font-size: 8.5pt" face="Arial" color="#000000">
				  <input type="checkbox" name="treat_water_safe<?php echo $i;?>[]" id="treat_water_safe<?php echo $i;?>[]" value="Let it stand and settle" /></font></td>
				  <td width="71" align="center"><font style="font-size: 8.5pt" face="Arial" color="#000000">
				    <input type="checkbox" name="treat_water_safe<?php echo $i;?>[]" id="treat_water_safe<?php echo $i;?>[]" value="DDFU">
				  </font></td>
					<td width="117" align="center"><font style="font-size: 8.5pt" face="Arial" color="#000000">
					 <!-- <input type="checkbox" name="treat_water_safe<?php //echo $i;?>[]" id="treat_water_safe<?php //echo $i;?>[]" value="" onClick="enable_other(this.checked)">-->
					  <input type="text" name="treat_water_safe_other<?php echo $i;?>" id="treat_water_safe_other<?php echo $i;?>" class="txt5" value="" /></font></td>
				</tr>
				<?php  $i++;
				} ?>
				</table>
				</div>
			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td><font style="font-size: 8.5pt; font-style: normal" face="Verdana" color="#FF0000">
				&nbsp;&nbsp;</font>			</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
		</tr>
		<tr>
			<td>
			<p align="center">
			<input type="submit" value="Click for Continue" name="submit" style="font-size: 8pt; font-family: Verdana; border-style: solid; border-width: 1px" /></p>
			</td>
		</tr>
		
	</table>
	</form>
</div>

</body>
</html>
